﻿package frEngine.animateControler.uvControler
{
    import __AS3__.vec.*;
    import baseEngine.core.*;
    import flash.events.*;
    import frEngine.*;
    import frEngine.animateControler.*;
    import frEngine.animateControler.keyframe.*;
    import frEngine.event.*;

    public class UVCenterScaleControler extends MeshAnimateBase
    {
        private var centerU:Number = 0.5;
        private var centerV:Number = 0.5;
        private var Uenabled:Boolean = true;
        private var Venabled:Boolean = true;
        public var uvCenter:Vector.<Number>;

        public function UVCenterScaleControler()
        {
            return;
        }// end function

        public function reInit(param1:Number, param2:Number, param3:Boolean, param4:Boolean) : void
        {
            this.centerU = param1;
            this.centerV = param2;
            this.Uenabled = param3;
            this.Venabled = param4;
            if (this.uvCenter)
            {
                this.uvCenter[2] = this.centerU;
                this.uvCenter[3] = this.centerV;
            }
            return;
        }// end function

        override public function get type() : int
        {
            return AnimateControlerType.UVCenterScaleController;
        }// end function

        override protected function getBaseValue(param1:Pivot3D) : Object
        {
            return 1;
        }// end function

        override protected function setSurfaceHander(event:Event) : void
        {
            super.setSurfaceHander(event);
            this.reBuilderHander(null);
            FrEventDispatcher.instance.proxyAddEventListener(targetMesh.material, Engine3dEventName.MATERIAL_REBUILDER, this.reBuilderHander);
            return;
        }// end function

        private function reBuilderHander(event:Event) : void
        {
            if (targetMesh)
            {
                this.uvCenter = targetMesh.material.materialParams.uvSclaeCenter2;
                this.uvCenter[2] = this.centerU;
                this.uvCenter[3] = this.centerV;
            }
            return;
        }// end function

        override protected function setTargetProperty(param1) : void
        {
            var _loc_2:* = Number(param1);
            if (this.uvCenter)
            {
                _loc_2 = 1 / _loc_2;
                if (this.Uenabled)
                {
                    this.uvCenter[0] = _loc_2;
                }
                else
                {
                    this.uvCenter[0] = 1;
                }
                if (this.Venabled)
                {
                    this.uvCenter[1] = _loc_2;
                }
                else
                {
                    this.uvCenter[1] = 1;
                }
            }
            return;
        }// end function

        override public function dispose(param1:Boolean = true) : void
        {
            FrEventDispatcher.instance.proxyRemoveEventListener(targetMesh.material, Engine3dEventName.MATERIAL_REBUILDER, this.reBuilderHander);
            if (this.uvCenter)
            {
                this.uvCenter[0] = 1;
                this.uvCenter[1] = 1;
                this.uvCenter[2] = 0;
                this.uvCenter[3] = 0;
            }
            var _loc_2:Number = 0.5;
            this.centerV = 0.5;
            this.centerU = _loc_2;
            var _loc_2:Boolean = true;
            this.Venabled = true;
            this.Uenabled = _loc_2;
            super.dispose(param1);
            return;
        }// end function

    }
}
